%   Initialization
clear; close all; clc;
%   The size of the input_layer
input_layer_size  = 400;
%   The size of the output layer
hidden_layer_size = 25;
%   The number of the labels
num_labels = 10;
fprintf('Loading and Visualizing Data ...\n');
%   Load the data from the Mat --- X, y
load('data1.mat');
%   The number of the training examples
m = size(X, 1);
%   The random indices of the training examples
rand_indices = randperm(m);
%   Display the randomly selected 100 data from the training examples
displayData(X(rand_indices(1:100), :));
%   Pause the program
fprintf('Program paused. Press any key to continue.\n'); pause;
fprintf('Loading Saved Neural Network Parameters ...\n');
%   Load the weights into the variables Theta1 and Theta2
load('weights.mat');
%   Get the predictions
predicting = predict(Theta1, Theta2, X);
fprintf('\nTraining Set Accuracy: %f\n', mean(double(predicting == y)) * 100);
%   Pause the program
fprintf('Program paused. Press any key to continue.\n'); pause;
%   The random indices of the training examples
rp = randperm(m);
%   Compare the image one by one
for i = 1:m
    fprintf('Displaying Example Image\n');
    %   Display the current data from the training examples
    displayData(X(rp(i), :));
    %   Get the prediction
    pred = predict(Theta1, Theta2, X(rp(i),:));
    fprintf('Neural Network Prediction: %d (digit %d)\n', pred, mod(pred, 10));
    %   Pause the program
    fprintf('Program paused. Press any key to continue.\n'); pause;
end
